{% extends "base.html" %}

{% block content %}
<h2>Firmy</h2>
{% if user.get_profile.teacher %}
<a href="/companies/seize/all/">Przejmij wszystkie nieprzejęte wpisy</a>
{% endif %}
<table>
    <thead>
    <tr>
        <th>Nazwa</th>
        <th>Adres</th>
        {% if user.teacher %}
        <th></th>
        {% endif %}
        <th></th>
        <th></th>
    </tr>
</thead>
<tbody>
{% for main_branch in main_branches %}
    <tr>
        <th><strong><a href="/companies/list/{{ main_branch.id }}/">{{ main_branch.name }}</a></strong></th>
        <td>{{ main_branch.get_address }}</td>
        {% if user.teacher %}
            {% if main_branch.created_by.get_profile.is_student %}
        <td><a href="/companies/seize/{{ main_branch.id }}/">Przejmij</a></td>
            {% else %}
        <td/>
            {% endif %}
        {% endif %}
        <td><a href="/companies/show/{{ main_branch.id }}/">Pokaż</a></td>
        {% if user.teacher %}
        <td><a href="/companies/edit/{{ main_branch.id }}/">Edytuj</a></td>
        {% else %}
            {% ifequal main_branch.created_by.id user.id %}
            <td><a href="/companies/edit/{{ main_branch.id }}/">Edytuj</a></td>
            {% else %}
            <td/>
            {% endifequal %}
        {% endif %}
    </tr>
    {% if main_branch.branch_set.all %}
        {% for branch in main_branch.branch_set.all %}
            <tr>
                <th>{{ branch.name }}</th>
                <td>{{ branch.get_address }}</td>
                {% if user.teacher %}
                    {% if branch.created_by.get_profile.is_student %}
                <td><a href="/companies/seize/{{ branch.id }}/">Przejmij</a></td>
                    {% else %}
                <td/>
                    {% endif %}
                {% endif %}
                <td><a href="/companies/show/{{ branch.id }}/">Pokaż</a></td>
                {% if user.teacher %}
                <td><a href="/companies/edit/{{ branch.id }}/">Edytuj</a></td>
                {% else %}
                    {% ifequal branch.created_by.id user.id %}
                    <td><a href="/companies/edit/{{ branch.id }}/">Edytuj</a></td>
                    {% else %}
                    <td/>
                    {% endifequal %}
                {% endif %}
            </tr>
        {% endfor %}
    {% endif %}
    <tr><td colspan={% if user.teacher %}5{% else %}4{% endif %}><a href="/companies/new/{{ main_branch.id }}/">Dodaj filię</a></td></tr>
    {% endfor %}
    {% if single_branch %}
    <tr><td colspan={% if user.teacher %}5{% else %}4{% endif %}><a href="/companies/list/">Wróc do listy</a></td></tr>
    {% else %}
    <tr><td colspan={% if user.teacher %}5{% else %}4{% endif %}><a href="/companies/new/">Dodaj firmę</a></td></tr>
    {% endif %}
</tbody>
</table>
<a href="/companies/my/">Firmy dodane przeze mnie</a>
{% endblock %}

